<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员控制面板</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', sans-serif;
        }
        body {
            background-color: #f5f5f5;
        }
        .container {
            display: flex;
            min-height: 100vh;
        }
        .sidebar {
            width: 250px;
            background-color: #2c3e50;
            color: white;
            padding: 20px 0;
        }
        .sidebar h2 {
            text-align: center;
            padding-bottom: 20px;
            border-bottom: 1px solid #445566;
            margin-bottom: 20px;
        }
        .sidebar ul {
            list-style: none;
        }
        .sidebar li {
            padding: 12px 25px;
            cursor: pointer;
            transition: all 0.3s;
        }
        .sidebar li:hover, .sidebar li.active {
            background-color: #34495e;
        }
        .main-content {
            flex: 1;
            padding: 30px;
        }
        .section {
            display: none;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            padding: 25px;
            margin-bottom: 30px;
        }
        .section.active {
            display: block;
        }
        h3 {
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
            color: #2c3e50;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select, textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }
        button {
            background-color: #3498db;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s;
        }
        button:hover {
            background-color: #2980b9;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        th, td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        th {
            background-color: #f8f9fa;
            font-weight: bold;
        }
        tr:hover {
            background-color: #f8f9fa;
        }
        .action-buttons {
            display: flex;
            gap: 10px;
        }
        .edit-btn {
            background-color: #f39c12;
        }
        .edit-btn:hover {
            background-color: #e67e22;
        }
        .delete-btn {
            background-color: #e74c3c;
        }
        .delete-btn:hover {
            background-color: #c0392b;
        }
        .search-bar {
            display: flex;
            margin-bottom: 20px;
        }
        .search-bar input {
            flex: 1;
            margin-right: 10px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="sidebar">
            <h2>管理员控制台</h2>
            <ul>
                <li class="menu-item active" data-section="class-section">班级管理</li>
                <li class="menu-item" data-section="course-section">课程管理</li>
                <li class="menu-item" data-section="user-section">用户管理</li>
                <li class="menu-item" id="logout">退出登录</li>
            </ul>
        </div>
        
        <div class="main-content">
            <!-- 班级管理 -->
            <div class="section active" id="class-section">
                <h3>班级管理</h3>
                
                <h4>添加新班级</h4>
                <form id="add-class-form">
                    <div class="form-group">
                        <label for="class-name">班级名称</label>
                        <input type="text" id="class-name" required>
                    </div>
                    <button type="submit">添加班级</button>
                </form>
                
                <h4 style="margin-top: 30px;">删除班级</h4>
                <form id="delete-class-form">
                    <div class="form-group">
                        <label for="delete-class-name">班级名称</label>
                        <input type="text" id="delete-class-name" required>
                    </div>
                    <button type="submit">删除班级</button>
                </form>
            </div>
            
            <!-- 课程管理 -->
            <div class="section" id="course-section">
                <h3>课程管理</h3>
                
                <h4>添加新课程</h4>
                <form id="add-course-form">
                    <div class="form-group">
                        <label for="course-name">课程名称</label>
                        <input type="text" id="course-name" required>
                    </div>
                    <button type="submit">添加课程</button>
                </form>
                
                <h4 style="margin-top: 30px;">删除课程</h4>
                <form id="delete-course-form">
                    <div class="form-group">
                        <label for="delete-course-name">课程名称</label>
                        <input type="text" id="delete-course-name" required>
                    </div>
                    <button type="submit">删除课程</button>
                </form>
            </div>
            
            <!-- 用户管理 -->
            <div class="section" id="user-section">
                <h3>用户管理</h3>
                
                <h4>添加新用户</h4>
                <form id="add-user-form" action="/SetUser" method="post">
                    <div class="form-group">
                        <label for="user-name">用户名</label>
                        <input type="text" id="user-name"  name ="username" required>
                    </div>
                    <div class="form-group">
                        <label for="user-password">密码</label>
                        <input type="password" id="user-password" name ="password" required>
                    </div>
                    <select id="user-role" name="role" required>
                        <option value="">请选择角色</option>
                        <option value="tea">老师</option>
                        <option value="stu">学生</option>
                        <option value="root">管理员</option>
                    </select>
                    <button type="submit">添加用户</button>
                </form>
                
                <h4 style="margin-top: 30px;">删除用户</h4>
                <form id="delete-user-form">
                    <div class="form-group">
                        <label for="delete-user-name">用户名</label>
                        <input type="text" id="delete-user-name" required>
                    </div>
                    <button type="submit">删除用户</button>
                </form>
            </div>
        </div>
    </div>

    <script>
        // 菜单切换功能
        document.querySelectorAll('.menu-item').forEach(item => {
            item.addEventListener('click', function() {
                if (this.id === 'logout') {
                    // 处理登出逻辑
                    if (confirm('确定要退出登录吗？')) {
                        window.location.href = 'login.html';
                    }
                    return;
                }
                
                // 移除所有菜单项的active类
                document.querySelectorAll('.menu-item').forEach(i => {
                    i.classList.remove('active');
                });
                
                // 为当前菜单项添加active类
                this.classList.add('active');
                
                // 隐藏所有section
                document.querySelectorAll('.section').forEach(section => {
                    section.classList.remove('active');
                });
                
                // 显示对应的section
                const targetSection = this.getAttribute('data-section');
                document.getElementById(targetSection).classList.add('active');
            });
        });
        
        // 表单提交事件处理
        document.getElementById('add-class-form').addEventListener('submit', function(e) {
            e.preventDefault();
            alert('班级添加成功！');
            this.reset();
        });
        
        document.getElementById('delete-class-form').addEventListener('submit', function(e) {
            e.preventDefault();
            alert('班级删除成功！');
            this.reset();
        });
        
        document.getElementById('add-course-form').addEventListener('submit', function(e) {
            e.preventDefault();
            alert('课程添加成功！');
            this.reset();
        });
        
        document.getElementById('delete-course-form').addEventListener('submit', function(e) {
            e.preventDefault();
            alert('课程删除成功！');
            this.reset();
        });
        

    </script>
</body>
</html>
